from starlette.authentication import requires
from starlette.endpoints import HTTPEndpoint
from starlette.responses import JSONResponse

from injection_service.restful.service import UserService
from injection_service.restful.service import OrderService


class UserController(HTTPEndpoint):
    async def get(self, request):
        return JSONResponse(await UserService.user_list(request))

    async def post(self, request):
        return JSONResponse(await UserService.create_user(request))

    async def put(self, request):
        return JSONResponse(await UserService.user_token(request))


class OrderController(HTTPEndpoint):
    @requires('authenticated')
    async def get(self, request):
        return JSONResponse(await OrderService.get_info(request))

    async def post(self, request):
        pass

    async def put(self, request):
        pass

    async def delete(self, request):
        pass